package com.acme.team02.chat.server;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import com.acme.team02.chat.server.connection.Connect;
import com.acme.team02.chat.server.domain.User;

public class UserManager {
	private CopyOnWriteArrayList<User> userList = new java.util.concurrent.CopyOnWriteArrayList<User>();
	

	public UserManager() {
		
	}

	/**
	 * Online users list
	 * @return
	 */
	public List<User> getUserList() {
		return Collections.unmodifiableList(userList);
	}
	
	/**
	 * Add user to online users list
	 * @param connect
	 */
	public void addUser (Connect connect) {
		userList.add(new User(connect, "user"+userList.size()));
	}
	
	/**
	 * Get user by connect
	 * @param connect
	 * @return
	 */
	public User getUser (Connect connect) {
		for (User user : userList) {
			if (user.getUserConnect() == connect) {
				return user;
			}
		}
		return null;
	}
	
		
}
